$(function () {


    if(_loginName==undefined||_token==undefined){
        window.location.href = "Login.html";
    }
    _loginName == undefined ? $(".userName").html("未登录") : $(".userName").html("管理员:" + _loginName);


    //头像显示隐藏与登录
    function adminHeader() {
        if ($(".userName").text() == "未登录") {
            $(".userc").click(function () {
                location.href = "Login.html"
            });

        }
        else {
            $(".userc").click(function () {
                $(".usercard").fadeToggle()
            });
        }
    }

    adminHeader()
    //....头像显示隐藏与登录


    //  管理员注销按钮
    $(".signOut").click(function () {
        delCookie("loginName");
        delCookie("token");
        location.href = "Login.html";

    });
    $("#HedgingStrategy").click(function () {
        $(".dcUl").css("display")=='none'?$(".dcUl").css({"display":"block"}):$(".dcUl").css({"display":"none"})
    })
    //导航改颜色
    function barClo(idName, imgSrc) {
        if(idName!="#HedgingStrategy li"){$(".dcUl").css({"display":"none"})}
        var count = $(".menuBar_ul a ").length;
        var color = "#0d87ba";
        for (var i = 0; i < 12; i++) {
            var _color = $(".menuBar_ul a").eq(i).find("li").css("background-color");
            if (_color == "rgb(13, 135, 186)") {
                var pngname = $(".menuBar_ul a ").eq(i).find("li img").attr("src");
                var pngZ = pngname.split(".");
                var newPng = pngZ[0] + "_." + pngZ[1];
                $(".menuBar_ul a ").eq(i).find("li img").attr({"src": newPng});
                break;
            }
        }
        $(".menuBar_ul a li").css({"background": "", "color": ""});
        $(idName).css({"background": "#0d87ba ", "color": "white"});
        $(idName + " img").attr({"src": imgSrc})
    }

    // function barClo() {
    //     if(idName!="#HedgingStrategy li"){$(".dcUl").css({"display":"none"})}
    //     var lis = document.querySelectorAll("#menubar li");
    //     var len = lis.length;
    //
    //     //切换页签样式：遍历li，给li绑定onclick事件
    //     for (var i = 0; i < len; i++) {
    //         lis[i].onclick = function () {
    //             //切换页签样式↓
    //             for (var i = 0; i < len; i++) {
    //                 if (lis[i] == this) {//判断是否为当前对象
    //                     lis[i].style.background = "#0d87ba";
    //                     lis[i].querySelector("a").style.color = "white";
    //                     var news_id = lis[i].querySelector("a").id;
    //                     // if (news_id == "list_news") {
    //                     //     $("#news_list").css("display", "block");
    //                     //     $("#news_import").css("display", "none");
    //                     // } else {
    //                     //     $("#news_list").css("display", "none");
    //                     //     $("#news_import").css("display", "block");
    //                     // }
    //                 } else {
    //                     lis[i].style.background = "white";
    //                     lis[i].querySelector("a").style.color = "black";
    //                 }
    //             }
    //         }
    //     }
    // }

    // 左侧导航添加内嵌页面
    //添加管理员页面
    $("#adminPage").click(
        function () {
            $(".centerTable iframe").attr({"src": "RoleList.html?loginName=" + _loginName + "&token=" + _token });
            barClo("#adminPage li", "img/admin.png")
        });
    //添加首页
    $("#homePage").click(
        function () {
            // $(".centerTable iframe").attr({"src": "RoleList.html"});
            barClo("#homePage li", "img/home.png")
        });
    //权限页面
    $("#adminPowerPage").click(
        function () {
            $(".centerTable iframe").attr({"src": "PermissionsList.html?loginName=" + _loginName + "&token=" + _token });
            barClo("#adminPowerPage li", "img/adminPower.png")
        });
    //注册用户管理
    $("#registeredUser").click(
        function () {
            $(".centerTable iframe").attr({"src": "UserList.html?loginName=" + _loginName + "&token=" + _token });
            barClo("#registeredUser li", "img/registeredUser.png")
        });
    //策略 持仓 调仓
    $("#strategy").click(
        function () {
            $(".centerTable iframe").attr({"src": "StrategyManagement.html?loginName=" + _loginName + "&token=" + _token });
            barClo("#strategy li", "img/strategy.png")
        });

    $("#SendKeyManagement").click(
        function () {
            $(".centerTable iframe").attr({"src": "SendKeyManagement.html?loginName=" + _loginName + "&token=" + _token});
            barClo("#SendKeyManagement li", "img/keyWord.png")
        });
    //对冲策略
    $("#HedgingStrategy").click(
        function () {
            barClo("#HedgingStrategy li", "img/doubleStock.png")
        });
    $("#HedgingStrategy1108").click(
        function () {
            $(".centerTable iframe").attr({"src": "HedgingStrategy.html?loginName=" + _loginName + "&token=" + _token+"&Strategy=1108"});
        });
    $("#HedgingStrategy1109").click(
        function () {
            $(".centerTable iframe").attr({"src": "HedgingStrategy.html?loginName=" + _loginName + "&token=" + _token+"&Strategy=1109"});
        });
    $("#HedgingStrategy1110").click(
        function () {
            $(".centerTable iframe").attr({"src": "HedgingStrategy.html?loginName=" + _loginName + "&token=" + _token+"&Strategy=1110"});
        });

    //收益概述
    $("#RevenueOverview").click(
        function () {
            $(".centerTable iframe").attr({"src": "RevenueOverview.html?loginName=" + _loginName + "&token=" + _token+"&strategyId=1001"});
            barClo("#RevenueOverview li", "img/ProfitToday.png")
        });
    //交易详情
    $("#TransactionDetails").click(
        function () {
            $(".centerTable iframe").attr({"src": "TransactionDetails.html?loginName=" + _loginName + "&token=" + _token});
            barClo("#TransactionDetails li", "img/Detailed.png")
        });
    //每日持仓&收益
    $("#DailyPositionsAndProfit").click(
        function () {
            $(".centerTable iframe").attr({"src": "DailyPositionsAndProfit.html?loginName=" + _loginName + "&token=" + _token+"&strategyId=1013"});
            barClo("#DailyPositionsAndProfit li", "img/trend.png")
        });
    //新闻
    $("#NewsDetailsTab").click(
        function () {
            $(".centerTable iframe").attr({"src": "NewsDetailsTab.html?loginName=" + _loginName + "&token=" + _token});
            barClo("#NewsDetailsTab li", "img/news.png")
        });
    //持仓跟踪
    $("#PositionTrackingList").click(
        function () {
            $(".centerTable iframe").attr({"src": "PositionTrackingList.html?loginName=" + _loginName + "&token=" + _token});
            barClo("#PositionTrackingList li", "img/track.png")
        });
    //调仓跟踪
    $("#WarehouseTrackingList").click(
        function () {
            $(".centerTable iframe").attr({"src": "WarehouseTrackingList.html?loginName=" + _loginName + "&token=" + _token});
            barClo("#WarehouseTrackingList li", "img/track.png")
        });

});